package com.project.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.project.bean.PostsBean;
import com.project.bean.ReplayBean;
import com.project.mapper.IPostsMapper;
import com.project.service.IPostsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDate;
import java.util.List;

@Transactional
@Service
public class PostsServiceImpl implements IPostsService {
    @Autowired
    private IPostsMapper mapper;
    /**
     * @param pageNO    页码
     * @param theme     主题
     * @param author    发帖人姓名
     * @param startDate 开始日期
     * @param endDate   结束日期
     * @return {@code IPage<PostsBean>}
     */
    @Override
    public IPage<PostsBean> selectByItem(Integer pageNO, String theme, String author, LocalDate startDate, LocalDate endDate,Integer channelId) {
        return mapper.selectByItem(new Page<>(pageNO,3),theme,author,startDate,endDate,channelId);
    }

    @Override
    public PostsBean selectPosts(Integer postsId) {
        PostsBean postsBean = mapper.selectPosts(postsId);
        List<ReplayBean> ls = mapper.selectReplays(postsId);
        postsBean.setReplays(ls);
        return postsBean;
    }

    @Override
    public void addPosts(PostsBean posts) {
        mapper.insert(posts);
    }
}
